﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SU.Center.Api.Handler.RBAC;
using SU.Center.Infa;

namespace SU.Center.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RBACsController : ControllerBase
    {
        private readonly IMediator _mediator;
        private readonly IHttpContextAccessor _contextAccessor;

        public RBACsController(IMediator _mediator, IHttpContextAccessor _contextAccessor)
        {
            this._mediator = _mediator;
            this._contextAccessor = _contextAccessor;
        }


        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> AddRole(InserUserInfoRepsultDto entity)
        {
            return await _mediator.Send(entity);
        }
      
        /// <summary>
        /// 显示角色与权限
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult> ShowRolesPermissions([FromQuery]ShowRolePermissionsRepsultDto entity)
        {
            return await _mediator.Send(entity);
        }

        /// <summary>
        /// 显示用户信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult> GetUserinfolsit([FromQuery]GetUSerListReqsultDto entity)
        {
            return await _mediator.Send(entity);
        }
        /// <summary>
        /// 添加角色权限
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> AddRolePermission(InserRolePermissionReqsultDto entity)
        {
            return await _mediator.Send(entity);
        }

        /// <summary>
        /// 新增权限
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> AddPermission(InserPermissionReqsultDto entity)
        {
            return await _mediator.Send(entity);
        }

        /// <summary>
        /// 删除权限
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult> DelPermission(DeletePermissionResultDto entity)
        {
            return await _mediator.Send(entity);
        }

        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult> DelRoles(DeleteRolesReqsultDto entity)
        {
            return await _mediator.Send(entity);
        }

        /// <summary>
        /// 删除用户信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult> DelUserInfos(DeleteUserInfoRepsultDto entity)
        {
            return await _mediator.Send(entity);
        }

        /// <summary>
        /// 树形
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult> GetTree([FromQuery] GetTreePermissionListRepsultDto entity)
        {
            return await _mediator.Send(entity);
        }
    }
}
